Skip to content

Home work2#2

Open
GeorgyMironov2001 wants to merge 4 commits intomainfrom
HomeWork2
Open

Home work2#2
GeorgyMironov2001 wants to merge 4 commits intomainfrom
HomeWork2

Conversation

@GeorgyMironov2001
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown
Collaborator

@vladkats vladkats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почти все методы реализованы некорректно. Пока принять не могу

@@ -0,0 +1,44 @@
package ru.sber.mironov;

public class Car {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не переопределил equals/hashcode

private final int power;
private final int ownerId;

public Car(long carId, String brand, String modelName, int maxVelocity, int power, int ownerId) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

разнести по строкам, читается тяжело когда много аргументов у конструктора в одну строку


import static java.util.stream.Collectors.toList;

public interface Garage {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Реализовать интерфейс это значит написать класс реализующий интерфейс, а не сделать дефолтные методы в интерфейсе и константы вместо полей

Comment on lines +8 to +12
HashMap<Owner, ArrayList<Car>> mapOwnerToCars = new HashMap<>();
HashMap<Car, Owner> mapCarToOwner = new HashMap<>();
HashMap<String, ArrayList<Car>> mapBrandToCar = new HashMap<>();
HashMap<Long, Car> cars = new HashMap<>();
HashMap<Long, Owner> owners = new HashMap<>();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

использовать интерфейс вместо реализации при объявлении полей.

ArrayList<Car> sorted = new ArrayList<>();
for (Car car : cars.values()) {
sorted.add(car);
sorted.sort(Comparator.comparingInt(Car::getMaxVelocity));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сортировка минимум O(n log n), а надо меньше чем за O(n)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (sorted.size() > 3) {
sorted.remove(0);
}
Там дальше идет этот код, который не даёт массиву иметь размер больше 3
Значит во врем сортировки мы будем тратить не более константы операций, а именно не более 9 операций. Суммарная сложность никак не O(nlogn).


@Before
public void setUpOwnersAndCars() {
Owner o0 = new Owner(6789, "Anton", "qu", 102);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем столько исходных данных? Ты не тестишь разные кейсы. А если тестишь, то нужно выносить в отдельный тест каждый кейс.

HashMap<Long, Owner> owners = new HashMap<>();

default Collection<Owner> allCarsUniqueOwners() {
return mapOwnerToCars.keySet().stream()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

будет неправильно работать из-за отсутствия equals/hashcode

* Complexity should be O(1)
*/
default Collection<Car> allCarsOfOwner(Owner owner) {
return mapOwnerToCars.get(owner);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

будет неправильно работать из-за отсутствия equals/hashcode

* Complexity should be O(1)
*/
default Collection<Car> allCarsOfBrand(String brand) {
return mapBrandToCar.get(brand);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

будет неправильно работать из-за отсутствия equals/hashcode

*
* @return removed car
*/
default Car removeCar(int carId) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

будет неправильно работать из-за отсутствия equals/hashcode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants